﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Configuration;
using Quartz;
using Anay.TaskScheduling.Job;

namespace Anay.TaskScheduling.Common
{
    public class JobFactory
    {
        private IJob job = null;

        public JobFactory()
        {
            string settings = ConfigurationManager.AppSettings["JobInfo"].ToString();
            var isLoadExternalModule = bool.Parse(ConfigurationManager.AppSettings["isLoadExternalModule"].ToString());
            if (isLoadExternalModule)
            {
                if (!string.IsNullOrWhiteSpace(settings))
                {
                    Type t = Type.GetType(settings, true);
                    if (t != null)
                    {
                        job = Activator.CreateInstance(t) as IJob;
                    }
                }
            }
            //默认实例BaseJob
            if (job == null)
                job = new BaseJob();
        }

        public IJob GetInstance()
        {
            return job;
        }
    }
}
